﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using CommonLib;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Payment.API.ViewModel;

namespace Payment.API.Controllers.QRCode
{
    [Route("api/v1/[controller]")]
    [ApiController]
    public class QRCodeApiController : ControllerBase
    {
        public QRCodeApiController()
        {
        }
        [HttpPost]
        [Route("QRCode")]
        public ActionResult<StringContent> CreateQRCodeAsync([FromBody] QRCodeRequest request)
        {
            var qrCode = new QRCodeHelper();
            var image = qrCode.GenerateQRCode(request.QRCode, request.QRCodeDescription);
            StringContent content = new StringContent("data:image/jpeg;base64," + Convert.ToBase64String(image));
            return Ok(content);
        }
        [HttpPost]
        [Route("QRCodeImg")]
        public ActionResult<StringContent> CreateQRCodeImgAsync([FromBody] QRCodeRequest request)
        {
            var qrCode = new QRCodeHelper();
            var image = qrCode.GenerateQRCode(request.QRCode, request.QRCodeDescription);
            return new FileContentResult(image, "image/jpg");
        }
    }
}
